const paths = require("path");
const url = require("url");
const fs = require("fs");

const resolveApp = relativePath => paths.resolve(process.cwd(), relativePath);
const pkg = require(resolveApp("package.json"));
const ENV_DOMAIN = pkg.ENV_DOMAIN ? "//" + pkg.ENV_DOMAIN : "";
const assetsPath = pkg.assetsPath ? "/" + pkg.assetsPath.replace(/(^\/*)|(\/*$)/g, "") : "";
const buildPath = "build/" + assetsPath;

module.exports = {
  dotenv: resolveApp(".env"),
  appPath: resolveApp("."),
  appBuild: resolveApp(buildPath),
  appPublic: resolveApp("public"),
  appHtml: resolveApp("public/index.html"),
  appIndexJs: fs.existsSync("src/index.ts")
    ? resolveApp("src/index.ts")
    : resolveApp("src/index.js"),
  appPackageJson: resolveApp("package.json"),
  appSrc: resolveApp("src"),
  appNodeModules: resolveApp("node_modules"),
  appAssets: resolveApp("src/app/assets"),
  appConfigs: resolveApp("src/app/config"),
  appStore: resolveApp("src/app/model"),
  appRouter: resolveApp("src/app/router"),
  appService: resolveApp("src/app/service"),
  appUtil: resolveApp("src/app/util"),
  appView: resolveApp("src/app/view"),
  appApi: resolveApp("src/app/api"),
  assetsPath: assetsPath,
  envDomain: ENV_DOMAIN,
  appName: pkg.name
  // appAssets: resolveApp('src/app/assets'),
  // servedPath: getServedPath(resolveApp('package.json'))
};
